1. Field of the Invention
The present invention relates to a method and an apparatus for concurrency control in a database system, in which timestamps are attached to a plurality of transactions in order to control the order of their executions.
2. Description of the Background Art
It is custom nowadays to utilize on-line processing using a computer for management of bank accounts, management of airplane seat reservations, and other such processings.
In the computer, various information such as that on each bank account or that on a state of seat reservations is stored in a form of a database. In such a database system, operations such as a transfer to a bank account and a confirmation of a seat reservation are performed as a job in which a computer accesses the database. Such a job in the database system has somewhat different characteristics from ordinary computer jobs, so that it is customarily called a transaction in order to make this distinction clear.
Now, in a computer system of an ample capacity used for such a database system, it is usual that a plurality of transactions are concurrently executed in order to improve its processing efficiency. In such a case, it is known that if an access to the database by each transaction is allowed freely, the consistency among the data can be destroyed. To prevent such trouble, a database manager for a database system is normally equipped with a scheduler which orders the read and write instructions issued by a plurality of transactions in such a manner as to maintain the consistency among the data. Such an operation by the scheduler is called a concurrency control.
There are various methods proposed for the concurrency control in the database system, of which two most popular methods being a so called two phase lock method and a timestamp ordering method. In particular, the timestamp ordering method is suitable for parallel processings, so that a dispersed database system can easily be realized with this method, as the schedulers for different sites of such a dispersed database system have no need to communicate each other in the timestamp ordering method.
In the timestamp ordering method, every transaction Ti is attached with a timestamp ts(Ti) which indicate a time this transaction Ti has started, such that this timestamp ts(Ti) is attached to each one of the read and write instructions issued by this transaction Ti in a course of its execution. Here, with respect to a particular data item x in the database, a timestamp max.sub.-- w[x] of the last write instruction which had given a latest renewal of this data item, and a timestamp max.sub.-- r[x] of the last read instruction which had read this data item most recently are recorded in the database system. The concurrency control is achieved by allowing an access to the data item x in response to a read instruction issued by the transaction Ti only when a condition: EQU ts(Ti)&gt;max.sub.-- w[x] (1)
can be satisfied. Likewise, an access to the data item x in response to a write instruction issued by the transaction Ti is allowed only when a condition: EQU ts(Ti)&gt;max.sub.-- w[x], and ts(Ti)&gt;max.sub.-- r[x] (2)
can be satisfied. In a case these conditions are not satisfied, the transaction Ti is rolled back to obtain a new timestamp and repeat the process all over again from the beginning. Thus, the instructions for accessing the same data item are ordered according to their timestamps.
However, such a timestamp ordering method has been associated with the following drawback.
In general, a scale of each transaction, i.e., a number of data items to be accessed and a time required for completing the data processing, is not necessarily uniform. For example, in a case of a banking system, in addition to an ordinary calculation processing such as a transfer to each bank account, there is also a so called information processing in which global information concerning a part or a whole of the database system is collected, in order to be utilized for instance in determining a strategy for system operation. Thus, the calculation processing requires only a small number of accesses, whereas the information processing requires a much greater number of accesses, which in some case amounts to accessing the entire database system.
Now, in such a large scale transaction of an information processing, even if the execution of the transaction can be performed without interruption due to interference from the other transaction, the time at which the execution is completed can be significantly later than its timestamp which is equal to the time at which the execution had started. In such a case, the aforementioned conditions (1) and (2) for the read and write instructions become progressively more difficult to satisfy toward the end of the execution, so that the larger transaction is less likely to be completed.